Skip to content

Fix required positional args#804

Merged
almarklein merged 10 commits intopygfx:mainfrom
Vipitis:required-params
Apr 22, 2026
Merged

Fix required positional args#804
almarklein merged 10 commits intopygfx:mainfrom
Vipitis:required-params

Conversation

@Vipitis
Copy link
Copy Markdown
Contributor

@Vipitis Vipitis commented Apr 6, 2026

fixes #803

I think this is a fix, but it is pretty awkward. The parsing logic for Attribute simply couldn't really distinguish between struct field (dict members) and positional args for a function. because the required <-> optional logic is different between the two.

Maybe there should be another class for Parameter instead?

I didn't check if any of the implementations of the native api need fixes, because some seem to validate defaults twice already example while the vast majority simply never handled an incorrectly passed None.

Python still won't necessarily raise anything more useful and the error comes from the native layer, unless you enforce typing.

@Vipitis Vipitis requested a review from Korijn as a code owner April 6, 2026 19:44
@almarklein
Copy link
Copy Markdown
Member

Maybe there should be another class for Parameter instead?

Since for descriptors we turn a struct into flat args, it makes sense (I think) to unify them.

I'm not sure if I was myself explicitly aware of how it works:

  • in structs, fields are optional by default, unless marked as required.
  • function parameters are required by default, unless marked as optional.

Copy link
Copy Markdown
Member

@almarklein almarklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, big improvement! I made some small tweaks to make the difference more explicit, and force Attribute to be instantiated with a source param.

@almarklein almarklein enabled auto-merge (squash) April 22, 2026 07:37
@almarklein almarklein merged commit 22a1e3d into pygfx:main Apr 22, 2026
20 checks passed
@Vipitis Vipitis deleted the required-params branch April 22, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

some required positional arguments default to None

2 participants